import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
        appBar: AppBar(title: const Text('你好Flutter')),
        //body内定义多个组件
        body: const Column(
          children: [
            MyApp(),
            SizedBox(height: 20,),
            Circular1(),
            SizedBox(height: 20,),
            Circular2(),
            SizedBox(height: 20,),
            LocalImage(),
          ],
        )
    ),
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        height: 150,
        width: 150,
        decoration: const BoxDecoration(
          color: Colors.yellow,
        ),
        //加载网络图片
        child: Image.network(
          "https://android-screenimgs.25pp.com/fs08/2021/07/01/11/110_38a77ab9b3cc6b4d9d2f08c13614f5f1.jpeg",
          // scale: 4, //图片缩放
          // alignment: Alignment.centerLeft,  //图片位置
          fit: BoxFit.cover, //图片填充策略
          repeat: ImageRepeat.repeatX, //图片重复策略
        ),
      ),
    );
  }
}

//实现圆形图片
class Circular1 extends StatelessWidget {
  const Circular1({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 150,
      height: 150,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(75),
          color: Colors.yellow,
          image: const DecorationImage(
            image: NetworkImage(
                "https://android-screenimgs.25pp.com/fs08/2021/07/01/11/110_38a77ab9b3cc6b4d9d2f08c13614f5f1.jpeg"),
            fit: BoxFit.cover,
          )
      ),
    );
  }

}

//实现圆形图片2
class Circular2 extends StatelessWidget {
  const Circular2({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: ClipOval(
        child: Image.network(
          "https://android-screenimgs.25pp.com/fs08/2021/07/01/11/110_38a77ab9b3cc6b4d9d2f08c13614f5f1.jpeg",
          width: 150,
          height: 150,
          fit: BoxFit.cover,
        ),
      ),
    );
  }
}

class LocalImage extends StatelessWidget {
  const LocalImage({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 150,
      width: 150,
      decoration: const BoxDecoration(
        color: Colors.yellow,
      ),
      child: Image.asset( //加载本地图片
        "images/01.jpg",
        fit: BoxFit.cover,
      ),
    );
  }
}

